#include "camera.h"

TCamera::TCamera( )
{ 
	lookAt( D3DXVECTOR3( 0, 0, 0 ), D3DXVECTOR3( 0, 0, 1 ), D3DXVECTOR3( 0, 1, 0 ) );
	setProjectionParams( D3DXToRadian( 65.0f ), 4.0f / 3.0f, 1.0f, 100.0f );
}

void TCamera::lookAt( const D3DXVECTOR3 &src
	       , const D3DXVECTOR3 &dst
	       , const D3DXVECTOR3 &aux
		   ) {
	// Save params
	position = src;
	target = dst;
	aux_up = aux;
	D3DXVECTOR3 front = target - position;
	distance_to_target = D3DXVec3Length( &front );

	// update view
    D3DXMatrixLookAtRH( &view, &position, &target, &aux_up );
}

void TCamera::setProjectionParams( float new_fov_in_radians
	                     , float new_aspect_ratio
	                     , float new_z_near, float new_z_far
						 ) {

	fov_in_radians = new_fov_in_radians;
	aspect_ratio   = new_aspect_ratio;
	z_near         = new_z_near;
	z_far          = new_z_far;

    D3DXMatrixPerspectiveFovRH( &projection
		                      , new_fov_in_radians, new_aspect_ratio
							  , new_z_near, new_z_far );

}
